package com.hyz.assetManager.listener;

import com.alibaba.fastjson.JSON;
import com.hyz.assetManager.service.AssetManagerService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import pojo.permissions.assetManager.AssetInboundRequest;


/**
 * @author HGD
 * @date 2022/9/30 12:53
 */
@Component
public class AssetManagerListener {
    @Autowired
    private AssetManagerService assetManagerService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "assetInbound.queue"),
            exchange = @Exchange(name = "assetManager", type = ExchangeTypes.DIRECT),
            key = {"assetInbound"}
    ))
    public void createAssetInbound(String massage) {
        AssetInboundRequest assetInboundRequest = JSON.parseObject(massage, AssetInboundRequest.class);
        assetManagerService.createAssetInbound(assetInboundRequest);
    }
}
